#!/bin/sh
## A script to wrap idlerpg for cron
# Run in crontab with:
# fyi, the irpg needs to be called from it's local dir, so link the wrapper there
# */30 * * * * /home/demure/irpg/irpg_wrapper.sh

IDLE_DIR="/irpg/"
IDLE_CMD="perl ${IDLE_DIR}irpg_bot.pl"
IDLE_PID="$(pgrep -f "${IDLE_CMD}" | wc -l)"

cd $IDLE_DIR
if [ "${IDLE_PID}" -eq "0" ]; then
    ${IDLE_CMD} 2>&1 1>/dev/null
  else
    if [ "${IDLE_PID}" -gt "1" ]; then
        pkill -f "${IDLE_CMD}"
        ${IDLE_CMD} 2>&1 1>/dev/null
    fi
fi
